import json
import numpy as np
from argparse import ArgumentParser

def majority_vote(scores):
    scores = [item.lower() for item in scores]
    final_answer = max(set(scores), key=scores.count)
    return True if final_answer == 'yes' else False

def evaluate(data):
    # panda: 参考answer和predict是否一致（忽略大小写和前后空格）
    panda_results = [
        item['answer'].strip().lower() == item['predict'].strip().lower()
        for item in data
    ]
    # gpt: 采用majority_vote
    gpt_results = [majority_vote(item['score']) for item in data]
    return {
        'panda': np.mean(panda_results) * 100,
        'gpt': np.mean(gpt_results) * 100
    }

def main():
    parser = ArgumentParser()
    parser.add_argument('--src_file', required=True)
    args = parser.parse_args()

    data = []
    with open(args.src_file, 'r', encoding='utf-8') as f:
        for line in f:
            data.append(json.loads(line.strip()))

    result = evaluate(data)
    print(f"panda: {result['panda']:.2f}")
    print(f"gpt: {result['gpt']:.2f}")

if __name__ == '__main__':
    main()